﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Net.Mail;

namespace BaoJian.Info
{
    public partial class join : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Save_Click(object sender, EventArgs e)
        {
            MailAddress MessageFrom = new MailAddress("lyq628@163.com");   //发件人邮箱地址
            string MessageTo = "lyq628@163.com";   //收件人邮箱地址
            string MessageSubject = "加盟信息";         //邮件主题\
            string body = "{0}<br> {1}-{2}<br>{3}<br>{4}<br>";
            string MessageBody = string.Format(body, AuthorName.Text, Tel_area.Text, Tel_number.Text, Mobile.Text, Content.Text);
                         
            if (Send(MessageFrom, MessageTo, MessageSubject, MessageBody))
            {
                //Response.Write("发送邮件成功");
                SubmitOK.Text = "提交成功";
                AuthorName.Text = "";
                Tel_area.Text = string.Empty;
                Tel_number.Text = string.Empty;
                Mobile.Text = string.Empty;
                Content.Text = string.Empty;
                
            }
            else
            {
                //Response.Write("发送邮件失败");
                SubmitOK.Text = "提交失败";
            }
        }

        public bool Send(MailAddress MessageFrom, string MessageTo, string MessageSubject, string MessageBody)
        {
            MailMessage message = new MailMessage();

            message.From = MessageFrom;
            message.To.Add(MessageTo);              //收件人邮箱地址可以是多个以实现群发
            message.Subject = MessageSubject;
            message.Body = MessageBody;
            message.IsBodyHtml = true;              //是否为html格式
            message.Priority = MailPriority.High;   //发送邮件的优先等级

            SmtpClient sc = new SmtpClient();
            sc.Host = "smtp.163.com";              //指定发送邮件的服务器地址或IP
            sc.Port = 25;                           //指定发送邮件端口
            sc.Credentials = new System.Net.NetworkCredential("lyq628@163.com", "gaotian"); //指定登录服务器的用户名和密码
            try
            {
                sc.Send(message);       //发送邮件
            }
            catch
            {
                return false;
            }
            return true;
        }
    }
}
